package cn.tedu.wms.passport.controller;

import cn.tedu.wms.passport.pojo.dto.AdminRoleAddNewDTO;
import cn.tedu.wms.passport.pojo.vo.AdminRoleListItemVO;
import cn.tedu.wms.passport.pojo.vo.AdminRoleStandardVO;
import cn.tedu.wms.passport.service.IAdminRoleService;
import cn.tedu.wms.passport.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/adminRoles")
@Api(tags = "02. 管理员角色关联管理模块")
public class AdminRoleController {

    @Autowired
    IAdminRoleService adminRoleService;

    @ApiOperation("添加管理员角色关联")
    @ApiOperationSupport(order = 100)
    @PostMapping("/add-new")
    public JsonResult<Void> addNew(AdminRoleAddNewDTO adminRoleAddNewDTO){
        log.info("开始处理添加管理员角色关联数据,参数:{}",adminRoleAddNewDTO);
        adminRoleService.addNew(adminRoleAddNewDTO);
        return JsonResult.ok();
    }

    @ApiOperation("删除管理员角色关联")
    @ApiOperationSupport(order = 200)
    @ApiImplicitParam(name = "id",value = "管理员id",required = true,dataType = "long")
    @PostMapping("/{id:[0-9]+}/delete")
    public JsonResult<Void> delete(@PathVariable Long id){
        log.info("准备删除的数据id:{}",id);
        adminRoleService.deleteById(id);
        return JsonResult.ok();
    }

    @ApiOperation("修改管理员角色关联")
    @ApiOperationSupport(order = 300)
    @PostMapping("/delete")
    public JsonResult<Void> update(AdminRoleStandardVO adminRoleStandardVO){
        log.info("准备删除的数据,参数:{}",adminRoleStandardVO);
        adminRoleService.updateById(adminRoleStandardVO);
        return JsonResult.ok();
    }

    @ApiOperation("查询管理员角色关联详情")
    @ApiOperationSupport(order = 400)
    @ApiImplicitParam(name = "id",value = "管理员id",required = true,dataType = "long")
    @GetMapping("/{id:[0-9]+}")
    public JsonResult<AdminRoleStandardVO> select(@PathVariable Long id){
        log.info("开始处理查询管理员角色关联详情,参数:{}",id);
        AdminRoleStandardVO queryResult = adminRoleService.getStandardById(id);
        return JsonResult.ok(queryResult);
    }

    @ApiOperation("查询管理员角色关联列表")
    @ApiOperationSupport(order = 500)
    @GetMapping("")
    public JsonResult<List<AdminRoleListItemVO>> list(){
        log.info("开始处理查询管理员角色关联列表");
        List<AdminRoleListItemVO> list = adminRoleService.list();
        return JsonResult.ok(list);
    }






}
